package com.yzy.fly.mapper;

import com.yzy.fly.entity.role.FlyProcessNode;
import com.yzy.fly.kernel.mapper.FlyBasicMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Collection;
import java.util.List;

@Mapper
public interface FlyProcessNodeMapper extends FlyBasicMapper<FlyProcessNode> {
    @Select("select * from fly_process_node a where a.id = #{id}")
    FlyProcessNode selectById(@Param("id") int id);

    @Select("select * from fly_process_node a where 1=1")
    List<FlyProcessNode> selectAll();

    @Select("select * from fly_process_node a where 1=1 and a.processId = #{processId} ")
    List<FlyProcessNode> selectAllByProcessId(@Param("processId") int processId);

    @Select("select * from fly_process_node a where 1=1 and a.systemId = #{systemId}")
    List<FlyProcessNode> selectAllBySystemId(@Param("systemId") int systemId);

//    @Select({"select * from fly_process_node a where 1=1 and a.classId = (select b.fieldId from fly_field_annotation b where b.id = #{annotationId})",
//    "","",""})
    @Select({"<script>",
            "select * ",
            "from fly_process_node a",
            "where 1=1",
            "<when test='componentId!=null'>",
            "AND a.componentId = #{componentId}",
            "</when>",
            "<when test='systemId!=null'>",
            "AND a.systemId = #{systemId}",
            "</when>",
            "</script>"})
    List<FlyProcessNode> selectAllByParentId(@Param("componentId") Integer componentId, @Param("systemId") Integer systemId);

    @Select("select * from fly_process_node a where 1=1 and a.name = #{name}")
    FlyProcessNode selectOneByName(@Param("name") String name);


    @Delete("delete a from fly_process_node a where a.processId = #{processId}")
    int deleteByProcessId(@Param("processId") Integer processId);

    /**
     * 批量插入（mysql）
     * @param entityList
     * @return
     */
    Integer insertBatchSomeColumn(Collection<FlyProcessNode> entityList);
}